global time "eventdate"

use localemployment${version}.dta, clear
qui: keep employment* employment_point* idtime eventdate 
qui: reshape long employment employment_point, i(idtime) j(amr)
qui: gen peak = 0
qui: replace peak = 1 if employment_point == 1
qui: gen trough = 0 
qui: replace trough = 1 if employment_point == -1
qui: keep idtime eventdate amr peak trough
qui: duplicates drop
qui: ren idtime cycle_start_date
merge 1:1 amr cycle_start_date using localcycles${version}.dta
qui: drop _merge  trough_date trough_val cycle_start_date cycle_start_val cyclesync
qui: drop cycle_end_date cycle_end_val ongoing_rec idtime id_lbc
qui: drop length_reces depth_reces length_recov depth_recov degree_reces degree_recov
merge 1:1 amr eventdate using  qoq_concentration_72_sa_${version}.dta
qui: drop if _merge!=3
qui: drop _merge

if "${var_x}"=="herfindahl_sa"{
di "take exponential of x"
qui: replace ${indep_var}=exp(${indep_var})
}
********************************************************************************
local varlist "peak trough"
foreach what of local varlist{
global dep_var "`what'" 
preserve
qui: do ${do}/FigLocalPeaksTroughs.do
qui: keep beta* lb* ub*
qui: duplicates drop
qui: gen aux = 1
qui: reshape long beta lb ub, i(aux) j(lag)
qui: label define lag_lbl 1 "4Q lag" 2 "3Q lag" 3 "2Q lag" 4 "1Q lag" 5 "`what'" 6 "1Q fwd" 7 "2Q fwd" 8 "3Q fwd" 9 "4Q fwd"
qui: label values lag lag_lbl
qui: gen yaxis = 0
twoway (line yaxis lag, lcolor(red)) (sc beta lag, connect(direct) lcolor(black) mcolor(black)) (rcap ub lb lag, lcolor(black)), xlabel(1(1)9, valuelabel) graphregion(color(white)) ytitle("TP probability on concentration") xtitle("") legend(off)
graph export ${graphs}/Figure3quarterlylogit${version}`what'.png, replace
restore
}
********************************************************************************
